package app

import (
    "github.com/BurntSushi/toml"
    "path/filepath"
)

const (
    FilePath = "./config.toml" //配置文件路径
)

var config *WebConfig

//站点配置
type WebConfig struct {
    Port         int            `toml:"port"`           //服务器端口
    RunMode      string         `toml:"run_mode"`       //服务器运行模式(debug,release,test)
    Token        string         `toml:"token"`          //token
    StaticUrlMap [][]string     `toml:"static-url-map"` //静态资源路径映射
    DbConfig     DatabaseConfig `toml:"database"`       //数据库配置
}

//数据库配置
type DatabaseConfig struct {
    Driver string `toml:"driver"` //数据库类型
    Url    string `toml:"url"`    //数据库连接串
}

//初始化配置文件
func initConfig() *WebConfig {
    fp, err := filepath.Abs(FilePath)
    if err != nil {
        panic(err)
    }
    config = new(WebConfig)
    _, err = toml.DecodeFile(fp, config)
    if err != nil {
        panic(err)
    }
    return config
}

//获取配置文件对象
func GetConfig() *WebConfig {
    return config
}
